package redis

import (
	"MyWeb/internal/config"
	"errors"
	"github.com/redis/go-redis/v9"
	"golang.org/x/net/context"
	"strconv"
)

func InitRedisDb(cfg *config.Configuration, RdbPoint **redis.Client) error {
	var Rdb *redis.Client
	num, _ := strconv.Atoi(cfg.Redis.Rdb)
	Rdb = redis.NewClient(&redis.Options{
		Addr:     cfg.Redis.RdbHost + ":" + cfg.Redis.RdbPort,
		Password: cfg.Redis.RdbPassword,
		DB:       num,
	})

	_, err := Rdb.Ping(context.Background()).Result()
	if err != nil {
		return errors.New("Pooled redis ping failed ")
	}
	*RdbPoint = Rdb
	return nil
}
